package com.situ.mybatis.test;

import java.util.List;

import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import com.situ.mybatis.entity.Banji;
import com.situ.mybatis.entity.Course;
import com.situ.mybatis.entity.Student;
import com.situ.mybatis.util.MyBatisUtil;

public class MyBatisTest2 {

	@Test
	public void testOne2One() {
		SqlSession sqlSession = MyBatisUtil.getSqlSession();
		List<Student> list = sqlSession.selectList("student.findStudentBanjiInfo");
		for (Student student : list) {
			System.out.println(student);
		}
	}
	
	
	@Test
	public void testOne2Many() {
		SqlSession sqlSession = MyBatisUtil.getSqlSession();
		Banji banji = sqlSession.selectOne("banji.findBanjiStudentInfo", 1);
		// 班级下面保存了这个班级所有的学生的集合
		List<Student> list = banji.getStudentList();
		System.out.println(banji);
	}
	
	@Test
	public void testMany2Many() {
		SqlSession sqlSession = MyBatisUtil.getSqlSession();
		Banji banji = sqlSession.selectOne("banji.findBanjiCourseInfo", "java1812");
		// 班级下面保存了这个班级所学习的课程的集合
		List<Course> list = banji.getCourseList();
		System.out.println(banji);
	}
	
	@Test
	public void test22() {
		SqlSession sqlSession = MyBatisUtil.getSqlSession();
		List<Student> list = sqlSession.selectList("student.findStudentBanjiCourseInfo");
		for (Student student : list) {
			Banji banji = student.getBanji();
			List<Course> courseList = banji.getCourseList();
			System.out.println(student);
		}
	}
	
}
